#include <iostream>
#include<string>
#include<stack>
using namespace std;
int main()
{
    int m = 0;
    string s;
    stack<int> st;
    cin >> m;
    while (m--)
    {
        cin >> s;
        if (s == "push")
        {
            int x = 0;
            cin >> x;
            st.push(x);
        }
        else if (s == "pop")
        {
            int x = 0;

            if (st.size()) st.pop();
        }
        else if (s == "empty")
        {
            if (st.size())
            {
                cout << "NO" << endl;
            }
            else
            {
                cout << "YES" << endl;
            }
        }
        else {
            if (st.empty())
            {
                cout << "empty" << endl;
            }
            else
            {
                cout << st.top() << endl;
            }
        }
    }
    return 0;
}